#include<bits/stdc++.h>
using namespace std;

bool check(int a)
{
	if(a==2||a==0||a==1||a==9)
		return true;
	else
		return false;
}

int main()
{
	int sum=0;
	for(int i=1;i<=2019;++i)
	{
		int a=-1,b=-1,c=-1,d=-1;
		if(i<10)
		{
			a=i%10;
		}
		else if(i>=10&&i<100)
		{
			a=i%10;
			b=i/10;
		}
		else if(i>=100&&i<1000)
		{
			a=i%10;
			b=i/10%10;
			c=i/100;
		}
		else
		{
			a=i%10;
			b=i/10%10;
			c=i/100%10;
			d=i/1000;
		}
		if(check(a)||check(b)||check(c)||check(d))
		{
			//cout<<"i="<<i<<" "<<"a="<<check(a)<<" "<<"b="<<check(b)<<" "<<"c="<<check(c)<<" "<<"d="<<d<<" "<<check(d)<<"\n";
			sum+=i;
		}
	}
	cout<<sum;
	return 0;
}
